//
//  WmcEditTeamMemberInfoItemView.swift
//  YPWatermarkCamera
//
//  Created by yupao_ios_macmini06 on 2022/9/15.
//

import UIKit

class WmcEditTeamMemberInfoBaseItemView: WmcBaseView {
    /// 左边标题
    var leftTitle: String? {
        didSet {
            guard let leftTitle = leftTitle else {
                return
            }
            self.leftTitleLabel.text = leftTitle
        }
    }

    override func makeUI() {
        addSubview(leftTitleLabel)
        addSubview(lineView)

        leftTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.top.equalTo(16)
            make.bottom.equalTo(-16)
            make.height.equalTo(25)
        }

        lineView.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }

    lazy var leftTitleLabel: UILabel = {
        let view = UILabel()
        view.textColor = UIColor.wmc_grayH2_323233
        view.font = 17.yp.uiFont
        return view
    }()

    lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.wmc_grayH19_F5F5F5
        return view
    }()
}

class WmcEditTeamMemberInfoAvatarItemView: WmcEditTeamMemberInfoBaseItemView {
    func configure(model: WmcTeamMemberDetailModel) {
        let member = WmcTeamMember(name: model.showName, img: model.avatar)
        avatarView.member = member
    }

    override func makeUI() {
        super.makeUI()

        addSubview(avatarView)

        avatarView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-16)
            make.height.width.equalTo(36)
        }
    }

    lazy var avatarView: WmcMemberAvatarView = {
        let view = WmcMemberAvatarView()
        return view
    }()
}

class WmcEditTeamMemberInfoNameItemView: WmcEditTeamMemberInfoBaseItemView {
    /// 备注
    var name: String? {
        didSet {
            guard let name = name else {
                return
            }
            self.nameLabel.text = name
        }
    }

    override func makeUI() {
        super.makeUI()

        addSubview(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-16)
        }
    }

    lazy var nameLabel: UILabel = {
        let view = UILabel()
        view.textColor = UIColor.wmc_grayH8_8A8A99
        view.font = 17.yp.uiFont
        return view
    }()
}

class WmcEditTeamMemberInfoNoteItemView: WmcEditTeamMemberInfoBaseItemView {
    /// 备注
    var note: String? {
        didSet {
            guard let note = note else {
                return
            }
            self.noteLabel.text = note
        }
    }

    override func makeUI() {
        super.makeUI()

        addSubview(noteLabel)
        addSubview(arrowImageView)

        arrowImageView.snp.makeConstraints { make in
            make.right.equalTo(-9)
            make.centerY.equalToSuperview()
            make.height.width.equalTo(24)
        }

        noteLabel.snp.makeConstraints { make in
            make.right.equalTo(arrowImageView.snp.left).offset(-10)
            make.centerY.equalToSuperview()
            make.left.equalTo(leftTitleLabel.snp.right).offset(8)
        }
    }

    func hiddenArrow(isHidden: Bool) {
        arrowImageView.isHidden = isHidden
        isUserInteractionEnabled = !isHidden
        if isHidden {
            noteLabel.snp.remakeConstraints { make in
                make.right.equalTo(-16)
                make.centerY.equalToSuperview()
                make.left.equalTo(leftTitleLabel.snp.right).offset(8)
            }
        } else {
            noteLabel.snp.remakeConstraints { make in
                make.right.equalTo(arrowImageView.snp.left).offset(-10)
                make.centerY.equalToSuperview()
                make.left.equalTo(leftTitleLabel.snp.right).offset(8)
            }
        }
    }

    lazy var noteLabel: UILabel = {
        let view = UILabel()
        view.textColor = UIColor.wmc_grayH8_8A8A99
        view.font = 17.yp.uiFont
        view.textAlignment = .right
        return view
    }()

    /// 箭头
    lazy var arrowImageView: UIImageView = {
        let imageView = UIImageView(image: "teamAlbumRightArrow".wmc_image)
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
}

class WmcEditTeamMemberInfoPhoneItemView: WmcEditTeamMemberInfoNameItemView {
    /// 手机号
    var phone: String? {
        didSet {
            guard let phone = phone else {
                return
            }
            nameLabel.text = phone
        }
    }
}

class WmcEditTeamMemberInfoDeleteItemView: WmcEditTeamMemberInfoBaseItemView {
    var text: String? {
        didSet {
            self.deleteBtn.title = text
        }
    }

    override func makeUI() {
        addSubview(deleteBtn)
        addSubview(lineView)

        deleteBtn.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.bottom.equalTo(-1)
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.height.equalTo(56)
        }

        lineView.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.height.equalTo(1)
            make.bottom.equalToSuperview()
        }
    }

    lazy var deleteBtn: WmcNormalButton = {
        let view = WmcNormalButton()
        view.backgroundColor = UIColor.wmc_white_FFFFFF
        view.font = 17.wmc_font
        view.textColor = UIColor.wmc_red_F54A45
        view.title = "删除"
        view.textAlignment = .center
        view.layer.cornerRadius = 4
        view.clipsToBounds = true
        return view
    }()
}

class WmcTeamManagementSwitchItemView: WmcEditTeamMemberInfoBaseItemView {
    var isSyn: Int? {
        didSet {
            guard let isSyn = isSyn else {
                return
            }
            // 无语接口字段不同步
            let isOn = (isSyn == 0) ? false : true
            self.switchView.isOn = isOn
        }
    }

    override func makeUI() {
        super.makeUI()

        addSubview(switchView)
        addSubview(coverButton)
        switchView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-16)
        }
        coverButton.snp.makeConstraints { make in
            make.top.equalTo(switchView.snp.top)
            make.left.equalTo(switchView.snp.left)
            make.right.equalTo(switchView.snp.right)
            make.bottom.equalTo(switchView.snp.bottom)
        }
    }

    lazy var switchView: UISwitch = {
        let view = UISwitch()
        view.onTintColor = UIColor.wmc_mainTheme
        view.isOn = false
        return view
    }()

    lazy var coverButton: UIButton = {
        let view = UIButton()
        return view
    }()
}

class WmcTeamManagementTeamIdItemView: WmcEditTeamMemberInfoBaseItemView {
    var teamId: String? {
        didSet {
            guard let teamId = teamId else {
                return
            }
            self.teamIdLabel.text = teamId
        }
    }

    override func makeUI() {
        super.makeUI()

        addSubview(teamIdLabel)
        addSubview(copyBtn)

        copyBtn.snp.makeConstraints { make in
            make.right.equalTo(-16)
            make.centerY.equalToSuperview()
        }
        teamIdLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(copyBtn.snp.left).offset(-8)
        }
    }

    private lazy var teamIdLabel: UILabel = {
        let view = UILabel()
        view.textColor = UIColor.wmc_grayH2_323233
        view.font = 17.yp.uiFont
        return view
    }()

    lazy var copyBtn: WmcNormalButton = {
        let view = WmcNormalButton()
        view.backgroundColor = UIColor.wmc_white_FFFFFF
        view.font = 14.yp.uiFont
        view.textColor = UIColor.wmc_blue_5290FD
        view.title = "复制"
        view.textAlignment = .center
        return view
    }()
}
